#include "Tutorial.h"

// Initialize the instance
Tutorial* Tutorial::m_pTutorialInstance = 0;

Tutorial::Tutorial(void)
{
}

Tutorial::~Tutorial(void)
{
}

Tutorial* Tutorial::GetInstance(void)
{
	// Create the instance if it doesn't exist
	if(!m_pTutorialInstance)
		m_pTutorialInstance = new Tutorial;

	// Return the singleton
	return m_pTutorialInstance;
}

void Tutorial::DeleteInstance(void)
{
	// If instance exist, delete it!
	if(m_pTutorialInstance)
	{
		delete m_pTutorialInstance;
		m_pTutorialInstance = NULL;
	}
}

void Tutorial::Initialize(void)
{
	// Get the instance of sprite manager
	m_pSpriteMan = SpriteManager::GetInstance();
	sTrigger = 0;
}

void Tutorial::LoadTutorial(short sCurrLevel)
{
	// Depending on the level, load the correct sprites
	if(sCurrLevel == 1)
	{
		sFirstStep = m_pSpriteMan->LoadSprite("TutorialSprites\\trackRule.png", D3DXVECTOR3(100, 200, 0), 1.0f);
		sSecStep = m_pSpriteMan->LoadSprite("TutorialSprites\\rotateRule.png", D3DXVECTOR3(100, 300, 0), 1.0f);
		sThirdStep = m_pSpriteMan->LoadSprite("TutorialSprites\\modeRule.png", D3DXVECTOR3(700, 300, 0), 1.0f);
		sFourthStep = m_pSpriteMan->LoadSprite("TutorialSprites\\WASDRule.png", D3DXVECTOR3(200, 500, 0), 1.0f);
		sFinalStep = m_pSpriteMan->LoadSprite("TutorialSprites\\powerUpRule.png", D3DXVECTOR3(600, 400, 0), 1.0f);
		sCurrentStep = sFirstStep;
	}
	else if(sCurrLevel == 2)
	{
		sFirstStep = m_pSpriteMan->LoadSprite("TutorialSprites\\deselectRule.png", D3DXVECTOR3(500, 350, 0), 1.0f);
		sSecStep = m_pSpriteMan->LoadSprite("TutorialSprites\\firewallRule.png", D3DXVECTOR3(600, 200, 0), 1.0f);
		sFinalStep = m_pSpriteMan->LoadSprite("TutorialSprites\\doorShieldRule.png", D3DXVECTOR3(300, 150, 0), 1.0f);
	}
	else if(sCurrLevel == 3)
	{
		sFirstStep = m_pSpriteMan->LoadSprite("TutorialSprites\\teslaRule.png", D3DXVECTOR3(500, 100, 0), 1.0f);
		sFinalStep = m_pSpriteMan->LoadSprite("TutorialSprites\\avoidTeslaRule.png", D3DXVECTOR3(300, 150, 0), 1.0f);
	}
	else if(sCurrLevel == 4)
	{
		sFirstStep = m_pSpriteMan->LoadSprite("TutorialSprites\\springBoardRule.png", D3DXVECTOR3(100, 100, 0), 1.0f);
		sFinalStep = m_pSpriteMan->LoadSprite("TutorialSprites\\avoidMineRule.png", D3DXVECTOR3(300, 150, 0), 1.0f);
	}
	else if(sCurrLevel == 5)
	{
		sFirstStep = m_pSpriteMan->LoadSprite("TutorialSprites\\acidRule.png", D3DXVECTOR3(200, 300, 0), 1.0f);
		sFinalStep = m_pSpriteMan->LoadSprite("TutorialSprites\\pistonRule.png", D3DXVECTOR3(300, 150, 0), 1.0f);
	}
}

void Tutorial::Update(void)
{
	// The trigger is set by our code in gameplay,
	// depending on a certain situation
	if(sTrigger == 0)
		sCurrentStep = sFirstStep;
	else if(sTrigger == 1)
		sCurrentStep = sSecStep;
	else if(sTrigger == 2)
		sCurrentStep = sThirdStep;
	else if(sTrigger == 3)
		sCurrentStep = sFourthStep;
	else if(sTrigger == 4)
		sCurrentStep = sFinalStep;
}

void Tutorial::RenderTutorial(void)
{
	// Rendering only one message at a time
	if(sTrigger > -1)
		m_pSpriteMan->DrawSprite(sCurrentStep);
}

void Tutorial::DestroyTutorial(void)
{
	// Destroying all the sprites
	for(int i = sFinalStep; i >= sFirstStep; i--)
		m_pSpriteMan->DestroySprite(i);
}